<?php
/*
# ------------------------------------------------------------------------
# JA Teline III - Version 1.3 - Licence Owner jSharing.COM
# ------------------------------------------------------------------------
# Copyright (C) Lifetime Joomla Just for Sharing, Ltd. All Rights Reserved.
# @license - Copyrighted Commercial Software
# Author: Joomla Just for Sharing
# Websites:  http://jsharing.com -  http://jsharing.net
# This file may not be redistributed in whole or significant part.
# ------------------------------------------------------------------------
*/

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

if (!class_exists('shadowboxClass')) {
	class shadowboxClass extends JAPopupHelper{
		// Modal name
		var $_modal_name;
		
		// Plugin params
		var $_pluginParams;
		
		// Param in {japopup} tag
		var $_tagParams;
		
		// Constructor
		function __construct($pluginParams){
			parent::__construct("shadowbox", $pluginParams);
			$this->_modal_name = "shadowbox";
			$this->_pluginParams = $pluginParams;
		}
		
		/**
		 * Get Library for ShadowBox
		 * @param 	Array	$pluginParams	Plugin paramaters
		 * @return 	String	Include JS, CSS string.
		 * */
		function getHeaderLibrary($bodyString){
				
			// Base path string
			$hs_base    = JURI::base().'plugins/system/plg_japopup/'.$this->_modal_name.'/';
			
			// Tag array
			$headtag    = array();				
			$headtag[] = '<link href="'.$hs_base.'shadowbox.css" type="text/css" rel="stylesheet" />';
			$headtag[] = '<script src="'.$hs_base.'shadowbox.js" type="text/javascript" ></script>';
			$headtag[] = '<script type="text/javascript" language="javascript" > 
							Shadowbox.init({players:  ["img", "html", "iframe", "swf"], 
							bgcolor: "#FFFFFF", 
							overlayColor: "'.$this->_pluginParams->get("group1-shadowbox-overlayColor").'", 
							viewportPadding: "'.$this->_pluginParams->get("group1-shadowbox-viewportPadding").'", 
							overlayOpacity: '.$this->_pluginParams->get("overlay_opacity").', 
							showOverlay: '.$this->_pluginParams->get("overlay").', 
							animate: '.$this->_pluginParams->get("group1-shadowbox-animate").',
							animSequence: "'.$this->_pluginParams->get("group1-shadowbox-animSequence").'",
							animateFade : "'.$this->_pluginParams->get("group1-shadowbox-animateFade").'" });  </script>';
				
			$bodyString = parent::getHeaderLibrary($bodyString, '/shadowbox.js', $headtag);
				
			return $bodyString;
		}
		
		/**
		 * Get content to display in Front-End.
		 * @param 	Array	$paras	Key and value in {japopup} tag
		 * @return 	String	HTML string to display
		 * */
		function getContent($paras, $content){			
			$arrData = parent::getCommonValue($paras, $content);
			
			// Generate random id
			$ranID = rand(0,10000);
			// To standard content
			$content = html_entity_decode($content);
			
			$modalGroup 	= $this->getValue("group");
			if(!empty($modalGroup))
				$modalGroup = '['.$modalGroup.']';		
			$arrData['group'] 	= $modalGroup;
			$arrData['rel']		= "shadowbox".$modalGroup;
			
			$type = $this->getValue("type");
			$str = "";
			switch ($type){
				case "ajax":
				case "iframe":
				case "image":{
					$str .= $this->showDataInTemplate("shadowbox", "default", $arrData);
					break;
				}
				
				case "slideshow":{
					$modalContent = explode(", ", $arrData['href']);
					foreach ($modalContent as $k=>$v){
						$image_url = trim($v);	
						$arrData['rel']	= "shadowbox[".$ranID."];options={counterType:'skip',continuous:true,animSequence:'sync'}";
						$arrData['href'] = $image_url;
						$arrData['content'] = "<img src=\"".$image_url."\" width=\"".$arrData['frameWidth']."\"/>";
						$str .= $this->showDataInTemplate("shadowbox", "default", $arrData);
					}
					break;
				}
				
				case "youtube":{
					$arrData['rel']	= "shadowbox".$modalGroup.";width=".$arrData['frameWidth'].";height=".$arrData['frameHeight'].";player=swf";
					$str .= $this->showDataInTemplate("shadowbox", "default", $arrData);
					break;
				}
			}
			
			// Return value string.
			return $str;
		}
	}
}
?>